package com.sanjiahantang.youjiarole.module.cases.adapters;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.module.cases.beans.CaseBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by zy on 2017/8/23.
 * 案例适配器
 */

public class CaseAdapter extends BaseAdapter {
    private Activity activity;
    private List<CaseBean.Data> mData;
    private LayoutInflater mInflater;
    private Picasso mPicasso;
    public CaseAdapter(Activity _activity, List<CaseBean.Data> _data){
        activity = _activity;
        mData = _data;
        mInflater = LayoutInflater.from(activity);
        mPicasso = Picasso.with(activity);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.item_case_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
        holder.bindData(mData.get(position));
        return convertView;
    }

    private class ViewHolder{
        private ImageView ivCaseMain,iv_case_collect;
        private TextView txtCaseTitle,tv_case_detail,tv_case_collectnum;
        public ViewHolder(View convertView) {
            ivCaseMain = (ImageView) convertView.findViewById(R.id.ivCaseMain);
            iv_case_collect = (ImageView) convertView.findViewById(R.id.iv_case_collect);
            txtCaseTitle = (TextView) convertView.findViewById(R.id.txtCaseTitle);
            tv_case_detail = (TextView) convertView.findViewById(R.id.tv_case_detail);
            tv_case_collectnum = (TextView) convertView.findViewById(R.id.tv_case_collectnum);
        }

        public void bindData(CaseBean.Data caseModel) {
            /*mPicasso.load(caseModel.getCasePhoto()).into(ivCaseMain);
            txtCaseTitle.setText(caseModel.getTitle());*/
        }
    }
}
